import go from 'gojs'

export function ddgInit(nodeDataArray, linkDataArray) {
	console.log(nodeDataArray, linkDataArray)
	var $ = go.GraphObject.make;  // for conciseness in defining templates
	var myDiagram =
		$(go.Diagram, "ddgDiagramDiv",  // must name or refer to the DIV HTML element
		{
		initialAutoScale: go.Diagram.Uniform,  // an initial automatic zoom-to-fit
		contentAlignment: go.Spot.Center,  // align document to the center of the viewport
		layout:
		$(go.TreeLayout,  // 垂直布局
		  { angle: 90, layerSpacing: 50 }) // 设置angle为90度，使布局垂直；layerSpacing用于设置垂直间距
	});
	// define each Node's appearance
	myDiagram.nodeTemplate =
		$(go.Node, "Auto",  // the whole node panel
		{ locationSpot: go.Spot.Center },
		// define the node's outer shape, which will surround the TextBlock
		$(go.Shape, "Rectangle",
		{ fill: $(go.Brush, "Linear", { 0: "rgb(254, 201, 0)", 1: "rgb(254, 162, 0)" }), stroke: "black" }),
		$(go.TextBlock,
		{ font: "bold 10px helvetica, bold arial, sans-serif", margin: 4 },
		new go.Binding("text", "label"))
		);

    myDiagram.linkTemplate =
        $(go.Link, {
            routing: go.Link.AvoidsNodes,
            curve: go.Link.Bezier,
            fromSpot: go.Spot.Right,
            toSpot: go.Spot.Left
        },
        new go.Binding("fromPortId", "fromPort"),
        new go.Binding("toPortId", "toPort"),
        $(go.Shape, {
            strokeWidth: 2,
            stroke: "black"
        },
        new go.Binding("strokeDashArray", "type", function(type) {
            return type === "Control" ? [4, 4] : null;
        })),
        $(go.Shape, {
            toArrow: "Standard",
            stroke: null
        }),
        $(go.TextBlock, {
            font: "bold 10pt helvetica, arial, sans-serif",
            stroke: "#333",
            segmentOffset: new go.Point(0, -10),
            segmentOrientation: go.Link.None
        },
        new go.Binding("text", "label")));
	myDiagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
    return myDiagram;
};